<?php

namespace app\admin\model;

use think\Db;
use think\Model;

class TestModel extends Model
{

    // 设置数据表（不含前缀）
    protected $name = 'test_data';
    // 设置当前模型对应的完整数据表名称
    protected $table = 'ld_test_data';

    public function __construct($data = [])
    {
        parent::__construct($data);
    }


    /**
     * @param $data
     * @param 添加案列
     */
    public function polist($data){
        $query = Db::name($this->name)->insert($data);
        return $query;
    }


    /**
     * @param 获取案列列表
     */
    public function problist($where,$pust,$page,$limit){
        $query = Db::name($this->name)->where($where)->where($pust)->page($page)->limit($limit)->order('id desc')->field('id,title,content,enable,types,addTime,updateTime')->select();
        return $query;
    }


    /**
     * @param $id
     * @param 获取当前案列
     */
    public function datalist($id){
        $query = Db::name($this->name)->where('id',$id)->find();
        return $query;
    }


    /**
     * @param $where
     * @param $data
     * @param 修改案列
     */
    public function edisont($where,$data){
        $query = Db::name($this->name)->where($where)->update($data);
        return $query;
    }


    /**
     * @param $where
     * @param 获取当前案列状态
     */
    public function exbut($where){
        $query = Db::name($this->name)->where($where)->find();
        return $query;
    }


    /**
     * @param $where
     * @param $data
     * @param 案列禁用、启用
     */
    public function eidtion($where,$data){
        $query = Db::name($this->name)->where($where)->update($data);
        return $query;
    }


    /**
     * @param $id
     * @param 删除案列
     */
    public function del($id){
        $query = Db::name($this->name)->where('id',$id)->delete();
        return $query;
    }

    /**
     * @param $where
     * @param $pust
     * @return mixed
     * @param 总条数
     */
    public function county($where,$pust){
        $query = Db::name($this->name)->where($where)->where($pust)->count();
        return $query;
    }


    /**
     * @param $where
     * @param 获取案例头条
     */
    public function Newtitle($where){
        $query = Db::name($this->name)->where($where)->field('id,title,types')->order("id desc")->find();
        return $query;
    }


    /**
     * @param $wheres
     * @param 获取简介头条
     */
    public function NewBrief($wheres){
        $query = Db::name($this->name)->where($wheres)->field('id,title,types')->order("id desc")->find();
        return $query;
    }


    /**
     * @param $where
     * @param 获取列表
     */
    public function beslist($where){
        $list = Db::name($this->name)->where($where)->field('id,title,addTime,types')->order('addTime desc')->paginate(6,false);
        $page = $list->render();
        return array("list"=>$list,"page"=>$page);
    }


    /**
     * @param $where
     * @param 获取当前案例信息
     */
    public function dlsist($where){
        $query = Db::name($this->name)->where($where)->field('id,title,content')->find();
        return $query;
    }

}